<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,height=device-height,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link rel="stylesheet" href="__ADMIN__/css/font.css">
    <link rel="stylesheet" href="__ADMIN__/css/xadmin.css">
    <script type="text/javascript" src="__ADMIN__/js/jquery.min.js"></script>
    <script type="text/javascript" src="__ADMIN__/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="__ADMIN__/js/xadmin.js"></script>
    <script type="text/javascript" src="__ADMIN__/js/cookie.js"></script>
    <link rel="stylesheet" href="/static/admin/css/font.css">
    <link rel="stylesheet" href="/static/admin/css/font-awesome.min.css">
    <style>
        .layui-form-item .layui-form-label {
            width: 120px;
        }

        .layui-form-item .layui-textarea {
            width: 190px;
        }

        #phone-one-div {
            display: none
        }

        .layui-anim {
            z-index: 99999 !important
        }
    </style>
</head>

<body>
<div class="x-body">
    <form class="layui-form">
        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">*</span>员工
            </label>
            <div class="layui-input-inline">
                <select name="admin_id" class="province-selector" lay-search lay-verify="required">
                    <option value="0">请选择员工</option>
                    {foreach $data['adminList'] as $key => $admin}
                    <option value="{$admin.id}">{$admin.name}</option>
                    {/foreach}
                </select>
            </div>
        </div>

        <div class="layui-form-item" >
            <label class="layui-form-label">
                <span class="x-red">*</span>聊天记录
            </label>


            <div class="layui-input-inline" style="width: 500px;">
                <div id="div1"></div>
                <textarea name="content" id="content" style="display:none">{$data.remarks}</textarea>
            </div>
        </div>


        <div class="layui-form-item">
            <label for="L_repass" class="layui-form-label">
            </label>
            <button type="button" class="layui-btn" lay-filter="add" lay-submit="">
                确定
            </button>
        </div>
    </form>
</div>

<script src="/static/admin/js/wangEditor.min.js"></script> <!-- v4的版本-->
<script>
    const E = window.wangEditor
    const editor = new E('#div1');
    const $text1 = $('#content');
    //        alert($text1.val())
    editor.config.onchange = function (html) {
        $text1.val(html);
//            alert(html)
    }
    editor.config.placeholder = '请输入聊天记录，图片或文字...';
    editor.config.height = 500;
    editor.config.menus = [
        'bold',
        'fontSize',
        'underline',
        'strikeThrough',
        'indent',
        'foreColor',
        'backColor',
        'justify',
        'undo',
        'redo',
        'image',
    ];

    editor.config.uploadImgServer = '/admin.php/Conf/uploadWang'//配置图片上传后台处理路径
    editor.config.uploadImgHooks = {
        // 上传图片之前
        before: function(xhr) {
            console.log(xhr)
        },
        // 图片上传并返回了结果，图片插入已成功
        success: function(xhr) {
            console.log('success', xhr)
        },
        // 图片上传并返回了结果，但图片插入时出错了
        fail: function(xhr, editor, resData) {
            console.log('fail', resData)
        },
        // 上传图片出错，一般为 http 请求的错误
        error: function(xhr, editor, resData) {
            console.log('error', xhr, resData)
        },
        // 上传图片超时
        timeout: function(xhr) {
            console.log('timeout')
        },
        // 图片上传并返回了结果，想要自己把图片插入到编辑器中
        // 例如服务器端返回的不是 { errno: 0, data: [...] } 这种格式，可使用 customInsert
        customInsert: function(insertImgFn, result) {
            // result 即服务端返回的接口
            console.log('customInsert', result)
            for (i =0; i< result.data.length; i++){
                // insertImgFn 可把图片插入到编辑器，传入图片 src ，执行函数即可
                console.log(result.data[i]);
                insertImgFn(result.data[i].url)
            }


        }
    };

    editor.create();
    $text1.val(editor.txt.html())

    layui.use(['form', 'layer', 'laydate', 'upload', 'layarea', 'rate'], function () {
        $ = layui.jquery;
        var form = layui.form
            , layer = layui.layer
            , laydate = layui.laydate
            , upload = layui.upload
            , layarea = layui.layarea
            , rate = layui.rate;

        laydate.render({
            elem: '#enable_time'
            , type: 'datetime'
        });

        //监听提交
        form.on('submit(add)', function (data) {
            if (data.field.admin_id === "0"){
                layer.msg('请选择员工', {icon: 2});
                return;
            }

            if (data.field.content === ''){
                layer.msg('请输入聊天记录', {icon: 2});
                return;
            }

            $.ajax({
                type: 'POST',
                dataType: 'json',
                data: data.field,
                url:"{:url('chat/edit')}",
                success: function (obj) {
                    layer.msg(obj.message, {icon: 1, time:2000}, function () {
                        // 获得frame索引
                        var index = parent.layer.getFrameIndex(window.name);
                        //关闭当前frame
                        parent.layer.close(index);
                        // 可以对父窗口进行刷新 
                        x_admin_father_reload();
                    });
                }
            });
            return false;
        });

    });
</script>
</body>

</html>